Skip to content

test(simple): don't overwrite a memory-mapped safetensors file on Windows - #359

Open
ArnabOPP wants to merge 1 commit into
AOSSIE-Org:mainfrom
ArnabOPP:fix/safetensors-test-windows
Open

ArnabOPP wants to merge 1 commit into
AOSSIE-Org:mainfrom
ArnabOPP:fix/safetensors-test-windows

Conversation

@ArnabOPP

@ArnabOPP ArnabOPP commented Nov 19, 2026 •

Copy link
Copy Markdown

test_verify_rejects_a_changed_safetensors_file fails on Windows. The test loads the exported file with safetensors.load_file, which keeps it memory-mapped on Windows, then saves the altered tensors over the same path. save_file fails with os error 1224 ("user-mapped section open"), so verify is never called.

The fix writes the altered weights to a second file, altered.safetensors, and verifies that. The test still checks that verify rejects a safetensors file whose weights differ from the chain. export_safetensors.py itself is unaffected, because it only reads the file.

Testing: On Windows 11, Python 3.11, CPU, tests/simple gave 128 passed and 1 failed before the change. test_export_safetensors.py now passes 7 of 7. I didn't re-run the full suite after the change, and I didn't run it on Linux.

This was found and fixed with Claude Code (Claude Sonnet 5.5). I ran the tests and reviewed the change myself.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Updated the changed-file verification test to check a separately saved file, leaving the original export unchanged.

…dows

test_verify_rejects_a_changed_safetensors_file loaded the exported file with
safetensors.load_file and then saved the altered tensors over the same path.
On Windows load_file keeps the file memory-mapped, so save_file fails with
os error 1224 before verify is ever called. Write the altered weights to a
second file instead; the test still checks that verify rejects a safetensors
file whose weights differ from the chain.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 11:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The changed-file verification test now saves modified tensors to altered.safetensors and expects verification of that file to raise SystemExit. It no longer overwrites the original export before verification.

Changes

Safetensors verification

Layer / File(s) Summary
Changed-file verification test
tests/simple/test_export_safetensors.py
The test saves modified tensors to altered.safetensors and expects verification of that file to raise SystemExit. It no longer overwrites the original export.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Other

Possibly related PRs

Suggested reviewers: ryoari, agarwalpranav0711

Merge Risk: Minimal · up to 39240

This is a test-only change that works around a Windows file-locking failure and still checks that verification rejects altered weights. It does not affect production behavior and is ready to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the test directory and the specific fix: the test no longer overwrites a memory-mapped safetensors file on Windows. The raw summary confirms the change writes altered tensors to altere…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the test directory and the specific fix: the test no longer overwrites a memory-mapped safetensors file on Windows. The raw summary confirms the change writes altered tensors to altered.safetensors in tests/simple/test_export_safetensors.py, which matches the title. The title is specific and concise, though the 'test(simple):' prefix is a conventional type tag and the title is slightly long at 73 characters.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1c63518 and 3924002.

Files selected for processing: 1

  • tests/simple/test_export_safetensors.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@gitcordapp

gitcordapp Bot commented Nov 19, 2026

Copy link
Copy Markdown

Link your account with Gitcord

Thanks for opening this PR, @ArnabOPP!

To receive Discord notifications and contributor tracking for this organization:

  1. Join Discord: https://discord.gg/hjUhu33uAn
  2. In Discord, run /link ArnabOPP
  3. Paste the verification code into your GitHub bio (or a public gist)
  4. Click Verify in Discord (or run /verify-link ArnabOPP)

Once linked, Gitcord can notify you about reviews, merges, and more.

— Posted by Gitcord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants